package com.coollang.smartbra.dialog;


import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.Window;

import com.coollang.smartbra.R;
import com.coollang.smartbra.views.SportAnalyzeView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @Auther: Timmy
 * @Data: 2017/9/19
 * @Fuction:
 */

public class SportAnalyzeViewDialog extends DialogFragment {

    @BindView(R.id.sport_analyze_view)
    SportAnalyzeView mSportAnalyzeView;
    private Dialog mDialog;
    private Unbinder unbinder;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        View customView = getActivity().getLayoutInflater().inflate(R.layout.sport_analyze_dialog, null);
        unbinder = ButterKnife.bind(this, customView);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(customView);

        mDialog = builder.create();
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

        return mDialog;
    }

    @Override
    public void onResume() {
        super.onResume();

        mSportAnalyzeView.setLevel(mOnSetLevel.level());

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.tv_confirm)
    public void onViewClicked() {
        mDialog.dismiss();
    }

    public static interface OnSetLevel {
        int level();
    }

    private OnSetLevel mOnSetLevel;

    public void setOnSetlevel(OnSetLevel onSetlevel) {
        mOnSetLevel = onSetlevel;
    }
}
